package com.netty.controller;

import com.netty.model.SocketSession;
import com.netty.session.SocketSessionManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author suzhen
 */
@Controller
public class IndexController {

    @Resource
    private SocketSessionManager socketSessionManager;

    @RequestMapping("")
    public String index(Map<String, Object> map,
                        @RequestParam(value = "send", defaultValue = "1") String send,
                        @RequestParam(value = "accept", defaultValue = "") String accept) {

        map.put("send", send);
        map.put("accept", accept);
        SocketSession[] socketSession = socketSessionManager.getSessions();

        List<SocketSession> socketSessions = Arrays.asList(socketSession);
        map.put("socketSessions", socketSessions);
        return "home/index/index.jsp";
    }

    @ResponseBody
    @RequestMapping("demo")
    public Object a() {
        return "a";
    }
}